<template>
	<view style="position: relative;">
		<u-navbar title='验收记录' bgColor="transparent" :autoBack='true' :placeholder="true"></u-navbar>
		<view class="content">
			<view style="width: 100%;height: 50vh;" v-if="getEvaluateList.length===0">
				<u-empty
				        mode="data"
				        icon="https://renovationcdn.jiachuangnet.com/empty.jpg"
						width="100%"
						height="100%"
				>
				</u-empty>
			</view>
			<u-swipe-action>
				<u-swipe-action-item v-for="(v,i) in getEvaluateList"  :key="v.evaluateId" show :options="options" @click="optionsFn($event,v)">
					<view class="item">	
						<view class="flex">
							<view class="label">名称：</view>
							<view class="val" style="font-size: 28rpx;font-weight: 700;">{{v.assignName}}</view>
						</view>
						<view class="flex" style="margin-top:30rpx;">
							<view class="label">地址：</view>
							<view class="val">{{v.address}}</view>
						</view>
						<view class="flex" style="margin-top:30rpx;">
							<view class="label">时间：</view>
							<view class="val">
								 {{v.acceptanceDate}}
							</view>
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
			<uni-load-more :status="status" v-show="getEvaluateList.length!=0"></uni-load-more>
		</view>
		<view v-show="getEvaluateList.length!=0" :style="{'color':color,'textAlign':'center'}" style="width:100%;position: absolute;bottom:180rpx;left:0">
			左滑，可进行更多操作
		</view>
		<!-- 监理 -->
		<view class="btn" v-if="isCheck==0&&loginType==2">
			<u-button :color='color' @click="toPath" shape="circle">新增验收</u-button>
		</view>
	</view>
</template>
<script>
	let app = getApp();
	export default {
		data() {
			return {
				color: app.globalData.defaultColor,
				getEvaluateList:[],
				options: [
					{
						text: '查看',
						style: {
							backgroundColor: '#13989a'
						}
					}
				],
				taskId:0,
				pageSize:5,
				pageNumber:1,
				total:1,
				status:'',
				loginType:null,
				isCheck:0
			}

		},
		onShow() {
			this.getEvaluateList=[]
			this.pageNumber=1
			this.getEvaluateListByTaskId()
		},
		onLoad(option) {
			this.taskId=option.assignTaskId
			this.loginType= uni.getStorageSync('loginType')
			this.isCheck=option.isCheck
		},
		// onPullDownRefresh() {
		// 	this.pageNumber=1
		// 	this.getEvaluateList=[]
		// 	this.getEvaluateListByTaskId()
		
		// },
		onReachBottom(){
			if(this.getEvaluateList.length>=this.total){
				this.status='noMore'
				return
			}
			this.pageNumber++
			this.getEvaluateListByTaskId()
		},
		methods:{
			deleteEvaluate(evaluateId){
				uni.$u.http.post('/evaluate/deleteEvaluate', {evaluateId}).then(res=>{
					console.log(res,'删除验收记录')
					this.pageNumber=1
					this.getEvaluateList=[]
					this.getEvaluateListByTaskId()
				})
			},
			optionsFn(e,msg){
				uni.navigateTo({
					url: `/pages/approval/index?evaluateId=${msg.evaluateId}&assignTaskId=${this.taskId}`
				});
			},
			getEvaluateListByTaskId(){
				this.status='loading'
				uni.$u.http.get('/evaluate/getEvaluateListByTaskId',{params:{
					taskId:this.taskId,
					pageSize:this.pageSize,
					pageNumber:this.pageNumber
				}}).then(res=>{
					console.log(res,'获取所有验收记录')
					this.getEvaluateList=[...this.getEvaluateList,...res.data]
					this.total=res.total
					if(this.getEvaluateList.length>=this.total){
						this.status='noMore'
					}else{
						this.status='more'
					}
				})
			},
			toPath(){
				let isEchoNewMsg=this.getEvaluateList.length===0?false:true
				uni.navigateTo({
					url:`/pages/approval/index?assignTaskId=${this.taskId}&isEchoNewMsg=${isEchoNewMsg}`
				})
			},
		}
	}
</script>

<style lang="scss" scopde>
	.btn {
		width: 660rpx;
		padding: 45rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 10;
		background-color: white;
		border-top: 1rpx solid #eee;
	}

	.content {
		padding-bottom: 220rpx;
	}

	.btn /deep/ .u-button {
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1)
	}

	.content {
		width: 700rpx;
		margin: 0 auto;
		margint-top: 30rpx;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.item {
		width: 660rpx;
		padding: 50rpx 20rpx;

	}
</style>